package game.roles.enemys;

import game.frame.MainFrame;
import game.roles.bullets.StarBullet;
import game.roles.visual.BackgroundMaps;
import game.roles.visual.Blast;
import game.utils.ImageChange;

import java.awt.*;
import java.util.Random;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.5.6
 * Time: 20:15
 * Description: boss
 */
public class Boss extends EnemyRole implements Bosses {
    /**
     * 敌人图片数组
     */
    public static Image[] bossImgArray;

    public static Image[] bossAttackImg;

    private ImageChange rm = new ImageChange(3);

    private int count;

    private int statue = 0;

    private final int GO_FRONT = 0;

    private final int GO_BACK = 1;


    public Boss() {
        super(2000, 250, 300, 300, 10000, 500);
    }

    @Override
    public void drawRole(Graphics graphics) {
        super.drawRole(graphics);
        graphics.setColor(Color.white);
        graphics.drawRect(this.x, this.y - 20, this.width, 10);
        graphics.fillRect(this.x, this.y - 20, (int) (this.hp * 1.0 / this.maxHp * this.width), 10);
    }

    @Override
    public void byHit(int deHp) {
        this.hp -= deHp;
        //怪物死亡时将怪物直接移除集合
        if (this.hp <= 0) {
            MainFrame.playerExp += this.exp;
            MainFrame.roleList.remove(this);
            System.out.println("boss死了");
            BackgroundMaps.mapMoveOrNot = true;
            setBoomWay();
        }
    }

    @Override
    public void rolesMove() {
        this.count++;
        if (count > 5) {
            if (statue == GO_FRONT) {
                this.x -= new Random().nextInt(5);
            } else if (statue == GO_BACK) {
                this.x += new Random().nextInt(5);
            }
            this.y += 10 - new Random().nextInt(20);
            if (this.x <= 300) {
                this.x = 300;
                this.statue = GO_BACK;
            }
            if (this.x >= 2000) {
                this.x = 1900;
                this.statue = GO_FRONT;
            }
            if (this.y >= 360) {
                this.y = 360;
            }
            if (this.y <= 200) {
                this.y = 200;
            }
            this.img = rm.change(bossImgArray);
            if (count > 50) {
                this.img = rm.change(bossAttackImg);
                MainFrame.roleList.add(new StarBullet(this.x + 10, this.y + 130, StarBullet.LEFT_UP));
                MainFrame.roleList.add(new StarBullet(this.x + 10, this.y + 130, StarBullet.LEFT_DOWN));
                MainFrame.roleList.add(new StarBullet(this.x, this.y + new Random().nextInt(40) + 140, StarBullet.FRONT));
                MainFrame.roleList.add(new StarBullet(this.x + 10, this.y + 130, StarBullet.LEFT_UP));
                MainFrame.roleList.add(new StarBullet(this.x + 10, this.y + 130, StarBullet.LEFT_DOWN));
            }
            if (count > 55) {
                count = 0;
            }
        }
    }


    /**
     * 击败最后的Boss后判定为成功
     */
    @Override
    public void setBoomWay() {
        super.setBoomWay();
        MainFrame.flag = false;
        MainFrame.isPass = true;
    }
}
